package com.zjh.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjh.admin.entity.DO.SysMenu;
import com.zjh.admin.mapper.SysMenuMapper;
import com.zjh.admin.service.ISysMenuService;
import com.zjh.common.annotation.RedisCacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 菜单表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-06-22
 */
@Service
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService {

    private final String key = "redis:key:test";
    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @Async
    @Override
    public void updateData() throws InterruptedException {
        List<SysMenu> data = getData();
        redisTemplate.opsForValue().set(key, data);
    }

    @Override
    @RedisCacheable()
    public List<SysMenu> getData() throws InterruptedException {
        Thread.sleep(6000);
        List<SysMenu> list = this.list();

        return list;
    }
}
